<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>

<body>
    <div id="app">
        <!-- 添加路由链接 -->
        <router-link to="/user/1">User1</router-link>
        <router-link to="/user/2">User2</router-link>
        <!-- 命名路由 -->
        <router-link :to="{name:'user',params:{id:3}}">User3</router-link>
        <router-link to="/register">Register</router-link>


        <!-- 路由占位符 （路由填充位） -->
        <router-view></router-view>
    </div>
    <script>
        const User = {
            props: ['id', 'uname', 'age'],
            // template: '<h1>User 组件 ---  用户ID为：{{$route.params.id}} -- 姓名：{{uname}} --- 年龄：{{age}}</h1>'
            template: '<h1>User 组件 ---  用户ID为：{{id}} -- 姓名：{{uname}} --- 年龄：{{age}}</h1>'
        }

        const Register = {
            template: '<h1>Register 组件</h1>'
        }

        const router = new VueRouter({
            routes: [{
                path: '/user/:id',
                //路由命名
                name: "user",
                component: User,
                props: route => ({
                    uname: 'heling',
                    age: 19,
                    id: route.params.id
                })
            }, {
                path: '/register',
                component: Register
            }]
        })

        const vm = new Vue({
            el: '#app',
            data: {},
            methods: {},
            router
        });
    </script>
</body>

</html>